cmake_minimum_required(VERSION 3.2)

include(cmake/CMakeDetermineGoCompiler.cmake)

set (ARROW_GO "go")
project (${ARROW_GO} VERSION 1.0.0 LANGUAGES "Go") 

list(APPEND CMAKE_LIBRARY_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../build/lib)

list(APPEND  CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/")
list(APPEND  CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

message("CMAKE_MODULE_PATH: ${CMAKE_MODULE_PATH}/")
set(OUTPUT_DIR ${PROJECT_BINARY_DIR}/CMakeFiles)

include(cmake/golang.cmake)
include(cmake/flags.cmake)

set(ARROW_BUILD_FOLDER 
    /codes/arrow/build
    # /media/data/apache/arrow/build
    # /usr/local/lib
    )

set(ARROW_DEBUG_STATIC_LIBS
    ${ARROW_BUILD_FOLDER}/debug/libarrow.a 
    ${ARROW_BUILD_FOLDER}/debug/libarrow_dataset.a
    ${ARROW_BUILD_FOLDER}/debug/libarrow_bundled_dependencies.a 
    ${ARROW_BUILD_FOLDER}/jemalloc_ep-prefix/src/jemalloc_ep/lib/libjemalloc.a
    ${ARROW_BUILD_FOLDER}/jemalloc_ep-prefix/src/jemalloc_ep/lib/libjemalloc_pic.a
    )

set(ARROW_SOURCE_FILES src/arrow/hi_arrow.go)
list(APPEND GO_SOURCE ${ARROW_SOURCE_FILES})
add_go_executable(hi_arrow ${ARROW_SOURCE_FILES})

set(HELLO_SOURCE_FILES src/helloworld/main.go)
list(APPEND GO_SOURCE ${HELLO_SOURCE_FILES})
add_go_executable(hello_world ${HELLO_SOURCE_FILES})

set(CGO_BYTES_SOURCE_FILES src/cgo/cgo_bytes.go)
list(APPEND GO_SOURCE ${CGO_BYTES_SOURCE_FILES})
# OUTPUT 设置为空时，可编译通过
# add_go_executable(alloc_bytes ${CGO_BYTES_SOURCE_FILES})

set(ARROW_CGO_SOURCE_FILES src/arrow/cgo/main.go)
list(APPEND GO_SOURCE ${ARROW_CGO_SOURCE_FILES})
add_go_executable(arrow_cgo ${ARROW_CGO_SOURCE_FILES})


set(ARROW_TBL_IO_SOURCE_FILES src/arrow/io/rw_file.go)
list(APPEND GO_SOURCE ${ARROW_TBL_IO_SOURCE_FILES})
add_go_executable(tbl_io ${ARROW_TBL_IO_SOURCE_FILES})


set(CALLOC_SOURCE_FILES src/arrow/demo/c_alloc_mem_demo.go)
list(APPEND GO_SOURCE ${CALLOC_SOURCE_FILES})
set(CMAKE_GO_FLAGS "--tags=ccalloc")
add_go_executable(calloc_demo ${CALLOC_SOURCE_FILES})

set(CMAKE_GO_FLAGS "")







# ADD_TARGET_LINK_LIBRARY(arrow_cgo "-L../../../build/lib -larrow_c")
# ADD_GO_HEADERS(arrow_cgo "-I../../../cc/src/include")

# set(ARROW_DEMO_C_ALLOC_FILES src/arrow/demo/c_alloc_mem_demo.go)
# list(APPEND GO_SOURCE ${ARROW_DEMO_C_ALLOC_FILES})

# target_link_libraries(calloc_demo static ${ARROW_DEBUG_STATIC_LIBS})
# add_go_executable(calloc_demo ${ARROW_DEMO_C_ALLOC_FILES})
